﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourDestination
    {
        public eTourDestination Data;
        public TourDestination()
        {
            Data = new eTourDestination();
        }
        ~TourDestination()
        { 
        }
        public virtual void Dispose()
        {
        }
        public int DeleteById(int ID)
        {
            int nResult = 0;
            cTourDestination objDAL = new cTourDestination();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public void LoadById(int ID)
        {
            cTourDestination objDAL = new cTourDestination();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }
        
        public int Insert()
        {
            int nResult = 0;
            cTourDestination objInfor = new cTourDestination();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourDestinationID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cTourDestination objInfor = new cTourDestination();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        
        private void MappingData(cTourDestination objInfor)
        {
            objInfor.RegionID = Data.RegionID;
            objInfor.Image = Data.Image;
            try { objInfor.TourDestinationDetail1 = Data.TourDestinationDetail1; }
            catch { objInfor.TourDestinationDetail1 = ""; }
            try { objInfor.TourDestinationDetail2 = Data.TourDestinationDetail2; }
            catch { objInfor.TourDestinationDetail2 = ""; }
            try { objInfor.TourDestinationDetail3 = Data.TourDestinationDetail3; }
            catch { objInfor.TourDestinationDetail3 = ""; }

            try { objInfor.TourDestinationTitle1 = Data.TourDestinationTitle1; }
            catch { objInfor.TourDestinationTitle1 = ""; }
            try { objInfor.TourDestinationTitle2 = Data.TourDestinationTitle2; }
            catch { objInfor.TourDestinationTitle2 = ""; }
            try { objInfor.TourDestinationTitle3 = Data.TourDestinationTitle3; }
            catch { objInfor.TourDestinationTitle3 = ""; }
        }
        private void ConvertData(cTourDestination objInfor)
        {
            Data.TourDestinationDetail1 = objInfor.TourDestinationDetail1;
            Data.TourDestinationDetail2 = objInfor.TourDestinationDetail2;
            Data.TourDestinationDetail3 = objInfor.TourDestinationDetail3;
            
            Data.TourDestinationTitle1 = objInfor.TourDestinationTitle1;
            Data.TourDestinationTitle2 = objInfor.TourDestinationTitle2;
            Data.TourDestinationTitle3 = objInfor.TourDestinationTitle3;
            Data.RegionID = objInfor.RegionID;
            Data.Image = objInfor.Image;
        }
        public DataTable Search(int RegionID, int CountryID)
        {
            DataTable tbResult = new DataTable();
            cTourDestination objDAL = new cTourDestination();
            tbResult = objDAL.Search(RegionID, CountryID);
            return tbResult;
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cTourDestination objDAL = new cTourDestination();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
    }

}
